//
//  SISSChooseCityLocationCell.m
//  SISSAPP
//
//  Created by 袁应荣 on 2018/9/13.
//  Copyright © 2018年 优房网. All rights reserved.
//

#import "SISSChooseCityLocationCell.h"


@interface SISSChooseCityLocationCell ()

@property (weak, nonatomic) UILabel *titleLabel;
@property (weak, nonatomic) UIButton *locationButton;
@property (weak, nonatomic) UIView *bottomLineView;

@end
@implementation SISSChooseCityLocationCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setTitleStr:(NSString *)titleStr {
    _titleStr = titleStr;
    self.titleLabel.text = titleStr;
}

- (void)startRotate {
    
    CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    //默认是顺时针效果，若将fromValue和toValue的值互换，则为逆时针效果
    animation.fromValue = [NSNumber numberWithFloat:0.f];
    animation.toValue = [NSNumber numberWithFloat: M_PI];
    animation.duration = 1;
    animation.autoreverses = NO;
    animation.fillMode = kCAFillModeForwards;
    animation.repeatCount = MAXFLOAT; //如果这里想设置成一直自旋转，可以设置为MAXFLOAT，否则设置具体的数值则代表执行多少次
    [self.locationButton.layer addAnimation:animation forKey:nil];
}

- (void)endRotate {
    
    [self.locationButton.layer removeAllAnimations];
}

- (void)locationButtonClickAction {
    
    if ([self.delegate respondsToSelector:@selector(locationButtonClickedAction)]) {
        [self.delegate locationButtonClickedAction];
    }
}

- (void)initUI {
    
    // 详细信息
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.font = [UIFont systemFontOfSize:14];
    titleLabel.textColor = MAIN_TEXT_COLOR;
    titleLabel.text = @"定位中";
    [self.contentView addSubview:titleLabel];
    self.titleLabel = titleLabel;
    
    // 选择按钮
    UIButton *locationButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [locationButton setImage:[UIImage imageNamed:@"zhankai"] forState:UIControlStateNormal];
    [locationButton addTarget:self action:@selector(locationButtonClickAction) forControlEvents:UIControlEventTouchUpInside];
    [locationButton setBackgroundImage:[PublicUtil imageWithColor:[UIColor clearColor] size:CGSizeMake(60, 60)] forState:UIControlStateNormal];
    [self.contentView addSubview:locationButton];
    self.locationButton = locationButton;

    
    UIView *lineView = [[UIView alloc] init];
    lineView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.contentView addSubview:lineView];
    self.bottomLineView = lineView;
}

- (void)initConstraint {
    [super initConstraint];
    
    // 自动布局
    WeakSelf
    CGFloat margin = 8.0;
    CGSize buttonSize = CGSizeMake(44, 44);
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(weakSelf.contentView).offset(margin);
        make.centerY.equalTo(weakSelf.contentView);
        make.left.equalTo(weakSelf.contentView).offset(margin * 2);
//        make.bottom.equalTo(weakSelf.bottomLineView.mas_top).offset(-margin);
    }];
    
    [self.locationButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(weakSelf.contentView);
        make.right.equalTo(weakSelf.contentView).offset(-margin * 2);
        make.size.mas_equalTo(buttonSize);
    }];
    
    [self.bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(weakSelf.contentView);
        make.height.mas_equalTo(1);
    }];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
